package com.yanghs.common.dao;

import com.yanghs.common.entity.hbm.Userinfo;
import org.springframework.orm.hibernate5.HibernateTemplate;

import java.util.List;

/**
 * @author yanghs
 * @Description:对hibernatetemplate的封装
 * @date 2018/3/14 23:02
 */
public class HibernateDao extends HibernateTemplate {

    public void test(){
        get(Userinfo.class,"1234");
    }
    public <T> T findObject(T t) throws Exception {
        List<T> tlist = findByExample(t);
        if(tlist.size() >1){
            throw new Exception("返回数据超过1，实际返回为："+tlist.size());
        }else if(tlist.size() == 1){
            return tlist.get(0);
        }
        return  null;
    }
}
